<?php

namespace App\Validation;

use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Numericality;

class AdsValidation extends BaseValidation
{
	public function initialize()
	{
		$this->add(
			"id",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"pos_id",
			new Numericality(
				  [
					  "message" => ":pos_id is required ",
					  "allowEmpty" => false,
				  ]
			)
		);

		$this->add(
			"go_url",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"title",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"short_title",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"pics",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"thumb",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"video",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"over_time",
			new PresenceOf(
				  [
					  "message" => ":over_time is required",
					  "allowEmpty" => false,
				  ]
			)
		);

		$this->add(
			"is_display",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"is_del",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
					  "allowEmpty" => true,
				  ]
			)
		);
        $this->add(
            "date_start",
            new PresenceOf(
                [
                    "message" => ":date_start is required",
                    "allowEmpty" => false,
                ]
            )
        );
        $this->add(
            "time_start",
            new PresenceOf(
                [
                    "message" => ":time_start is required",
                    "allowEmpty" => false,
                ]
            )
        );
        $this->add(
            "time_end",
            new PresenceOf(
                [
                    "message" => ":time_end is required",
                    "allowEmpty" => false,
                ]
            )
        );
        $this->add(
            "image_withurl",
            new PresenceOf(
                [
                    "message" => ":field is required",
                    "allowEmpty" => true,
                ]
            )
        );
        $this->add(
            "city_id",
            new PresenceOf(
                [
                    "message" => ":field is required",
                    "allowEmpty" => true,
                ]
            )
        );
	}

	//验证之前
	public function beforeValidation($data, $entity, $messages)
    {
    	$data->is_display = property_exists($data,'is_display') ? $data->is_display : 1;
    	$data->is_del = property_exists($data,'is_del') ? $data->is_del : 0;
    	
        return true;
    }
}